﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;

namespace IngredSubTool
{
    class PageSwitcher
    {
        public static MainWindow mainWindow;

        public static void Switch(UserControl newPage)
        {
            mainWindow.GoToPage(newPage);
        }
        public static void SwitchForward(UserControl newPage)
        {
            MainWindow.session.lastPage = MainWindow.session.currentPage;
            MainWindow.session.currentPage = newPage;
            //mainWindow.GoToPage(MainWindow.session.currentPage);
            if (MainWindow.session.previousPagesList == null)
            {
                MainWindow.session.previousPagesList.AddFirst(MainWindow.session.lastPage);
               
            }
            else
            {
            MainWindow.session.previousPagesList.AddLast(MainWindow.session.lastPage);
            }
            //MainWindow.session.addToPrevPageList(newPage);
            mainWindow.GoToPage(newPage);
        }
        public static void SwitchBack()
        {
            if (MainWindow.session.previousPagesList != null)
            {
                MainWindow.session.currentPage = MainWindow.session.previousPagesList.Last.Value;
               MainWindow.session.previousPagesList.RemoveLast();
                if (MainWindow.session.previousPagesList != null)
                {
                     MainWindow.session.lastPage = MainWindow.session.previousPagesList.Last.Value;
                }
                else
                {
                    MainWindow.session.lastPage = new SearchView();
                }

                //MainWindow.session.lastPage = MainWindow.session.currentPage;
                // MainWindow.session.currentPage = newPage;
                //mainWindow.GoToPage(MainWindow.session.currentPage);
                // MainWindow.session.previousPagesList.AddLast(MainWindow.session.lastPage);
                mainWindow.GoToPage(MainWindow.session.currentPage);
            }
            else
            {
                MainWindow.session.currentPage = new SearchView();
                SwitchForward(new SearchView());
            }
        }

        public static void GOBack()
        {

        }
    }
}
